#include <fstream>
#include <iostream>
#include <cassert>

static void fvecs_read(const char *path, float vecs[], int n, int d) {
    std::fstream fin(path, std::ios_base::binary | std::ios_base::in);
    assert(fin);

    int df; // read dimension in the file
    fin.read((char*)&df, sizeof(df));
    assert(df == d);

    int dummy; // dummy for one
    for (int i = 0; i < n; i++) {
        float *vec_i = vecs + i * d;
        fin.read((char*)vec_i, sizeof(*vecs) * d);
        fin.read((char*)&dummy, sizeof(dummy));
    }
}

static void ivecs_read(const char *path, int vecs[], int n, int d) {
    std::fstream fin(path, std::ios_base::binary | std::ios_base::in);
    assert(fin);

    int df; // read dimension in the file
    fin.read((char*)&df, sizeof(df));
    assert(df == d);

    int dummy; // dummy for one
    for (int i = 0; i < n; i++) {
        int *vec_i = vecs + i * d;
        fin.read((char*)vec_i, sizeof(*vecs) * d);
        fin.read((char*)&dummy, sizeof(dummy));
    }
}
